package com.pan.admin.module.visualizer.service.impl;

import java.time.LocalDate;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pan.admin.module.datareport.entity.StartTimeAndEndTime;
import com.pan.admin.module.visualizer.dao.LoanMarketVisualizerDao;
import com.pan.admin.module.visualizer.entity.vo.LoanMarketVisualizerVO;
import com.pan.admin.module.visualizer.service.LoanMarketVisualizerService;

/**
 * 贷超
 *
 * @author caoxin
 */
@Service
public class LoanMarketVisualizerServiceImpl implements LoanMarketVisualizerService {

    @Autowired
    private LoanMarketVisualizerDao loanMarketVisualizerDao;

    @Override
    @Transactional(readOnly = true)
    public List<LoanMarketVisualizerVO> list(StartTimeAndEndTime startTimeAndEndTime, String name) {

        String displayDateTime;
        //  拼接时间
        if (startTimeAndEndTime.ifNull()) {
            displayDateTime = "当日数据截止至" + LocalDate.now();
        } else {
            displayDateTime = startTimeAndEndTime.getStartTime() + "至" + startTimeAndEndTime.getEndTime();
        }

        startTimeAndEndTime.ifNullGen1();

        List<LoanMarketVisualizerVO> loanMarketList = this.loanMarketVisualizerDao.listLoanMarket(startTimeAndEndTime, name);

        loanMarketList.forEach(loanMarket -> {

            loanMarket.setDateTime(displayDateTime);
        });

        return loanMarketList;
    }

}
